package com.totoro.domain;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 多级资源 children下级资源 parent上级资源 只有是“叶子”接点，对应URL
 */
@Entity
@Table(name = "resource")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Resource extends BaseDomain {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String no;// 主键编号
	private String discription;// 描述

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "parent_no")
	private Resource parent;// 上级资源

	/*
	 * 1.一对多要添加mappedBy映射 2.FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
	 */
	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	private Collection<Resource> children;// 下级资源

	/*
	 * 1.一对多要添加mappedBy映射 2.FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
	 */
	@OneToMany(mappedBy = "resource",fetch = FetchType.LAZY)
	private Collection<RoleResource> roleResource;// 关联的RoleResource

	// 构造空的构造器
	public Resource() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getDiscription() {
		return discription;
	}

	public void setDiscription(String discription) {
		this.discription = discription;
	}

	public Resource getParent() {
		return parent;
	}

	public void setParent(Resource parent) {
		this.parent = parent;
	}

	public Collection<Resource> getChildren() {
		return children;
	}

	public void setChildren(Collection<Resource> children) {
		this.children = children;
	}

	public Collection<RoleResource> getRoleResource() {
		return roleResource;
	}

	public void setRoleResource(Collection<RoleResource> roleResource) {
		this.roleResource = roleResource;
	}

}